﻿
@{
    Layout = null;
    var returnUrl = Request.QueryString["returnUrl"];
    if (!string.IsNullOrEmpty(returnUrl)) {
        returnUrl = System.Web.HttpUtility.UrlDecode(returnUrl);
    }
}

<!DOCTYPE HTML>
<html lang="zh-lang">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="" content="yes" />
    <meta name="" content="black" />
    <link href="~/Content/css/tokenmall/css/styles.css" rel="stylesheet" />
    <link href="~/Content/css/tokenmall/css/special.css" rel="stylesheet" />
    <link href="~/Content/css/tokenmall/css/reg.css" rel="stylesheet" />

    <script src="~/Scripts/tokenmall/jquery-1.8.3.min.js"></script>
    <script src="~/Scripts/tokenmall/all.js?v=001"></script>
    <link href="~/Content/js/layer/1.9.3/layui.css" rel="stylesheet" />
    <script src="~/Content/js/layer/1.9.3/layer.js"></script>
    <title>邀请注册</title>
</head>
<body class="page-reg bg-white">
    <div class="box">
        <div class="ui-item flex mb30">
            <span class="ic">
                <i class="ic-reg1"></i>
            </span>
            <div class="flex-1">
                <div class="select relative fn-left">
                    <em class="icon-arrow absolute"></em>
                    <select class="col-red fn30 mobile_code">
                        <option>+86</option>
                        <option>+886</option>
                    </select>
                    <i class="fn-right"></i>
                </div>
                <div class="hidden">
                    <input class="ui-input fn28" id="phone" type="text" value="" placeholder="输入手机号">
                </div>
            </div>
        </div>
        <div class="ui-item flex mb30">
            <span class="ic">
                <i class="ic-reg2"></i>
            </span>
            <div class="flex-1">
                <input class="ui-input fn28" type="password" id="password" value="" placeholder="请输入登录密码">
            </div>
        </div>
        @*<div class="ui-item flex mb30">
            <span class="ic">
                <i class="ic-reg2"></i>
            </span>
            <div class="flex-1">
                <input class="ui-input fn28" type="password" value="" placeholder="请输入登录密码">
            </div>
        </div>*@
        <div class="ui-item flex mb30">
            <span class="ic">
                <i class="ic-reg3"></i>
            </span>
            <div class="flex-1">
                <input class="ui-input fn28" type="text" id="invitation_code" value="@ViewBag.invitationCode" placeholder="请输入邀请码">
            </div>
        </div>
        <div class="ui-item flex mb30">
            <span class="ic">
                <i class="ic-reg4"></i>
            </span>
            <div class="flex-1 relative">
                <input class="ui-input fn28" type="text" value="" id="yzm" placeholder="请输入验证码">
                <input type="hidden" name="token" value="" id="token" />
                <input type="button" class="yzm absolute fn28 col-red" value="获取验证码">
                <!-- <input type="button" class="yzm absolute fn28 col-gray" value="获取验证码"> -->
            </div>
        </div>
        <br><br>
        <div class="m">
            <div class="flex mb40">
                <a href="javascript:void(0)" class="ui-btn ui-btn-big ui-btn-buy flex-1"  id="autobtn">立即注册</a>
            </div>
            <div class="flex">
                <a href="/home/download" class="ui-btn ui-btn-big ui-btn-borderRed flex-1">下载拓垦</a>
            </div>
        </div>
    </div>
    <div id="popup"></div>
    <script src="https://cdn.dingxiang-inc.com/ctu-group/captcha-ui/index.js"></script>
    <script type="text/javascript">
        var myCaptcha;
        $(function () {
            myCaptcha = _dx.Captcha(document.getElementById('popup'), {
                appId: 'd857f517ea59f9c229a76b88aa938719',
                style: 'popup',
                success: function (token) {
                    $("#token").val(token);
                    myCaptcha.hide();
                    sendsms();
                }
            })
            var flag = false;
            $("#autobtn").click(function () {
                if (!checkMobile()) return;
                var mobile = $("#phone").val();
                var mobile_code = $(".mobile_code").val().replace("+", "");
                var code = $("#yzm").val();
                var invitation_code = $("#invitation_code").val();
                var password = $("#password").val();
                if (password.length < 6 || password.length > 16) { layer.msg("密码长度必须在6到16位"); return; }
                if (!/^(?![^a-zA-Z]+$)(?!\D+$)/.test(password)) { layer.msg("密码必须包含数字和字符"); return; }
                if (invitation_code.length == 0) { layer.msg("请填写身份证"); return; }
                if (code.length == 0) { layer.msg("请填写验证码"); return; }
                if (flag) return;
                flag = true;
                var data = { mobile: mobile, mobile_code: mobile_code, code: code, invitation_code: invitation_code, password: password, __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val() };
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/Home/RegisterAsync",//url
                    data: data,
                    success: function (result) {
                        if (result.result_code == 1000) {
                            layer.msg("注册成功");
                            setTimeout("window.location.href = '/home/download' + '@Html.Raw((!string.IsNullOrEmpty(returnUrl) ? "?returnUrl=" + System.Web.HttpUtility.UrlEncode(returnUrl) : ""))'", 1500);
                        } else {
                            layer.msg(result.result_msg);
                        }
                        flag = false;
                    },
                    error: function () {
                        layer.msg("异常！");
                        flag = false;
                    }
                });
            });
        });
        function sendsms() {
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/Home/GetCode",//url
                data: { mobile: $("#phone").val(), use_type: "token_register", mobile_code: $(".mobile_code").val().replace("+", ""), code_size: 6, code: $("#token").val() },
                success: function (result) {
                    if (result.result_code == 1000) {
                        layer.msg(result.result_msg);
                        new invokeSettime(".yzm");
                    }
                    else {
                        layer.msg(result.result_msg);
                        new invokeFn(".yzm", fn);
                    }
                },
                error: function () {
                    layer.msg("异常！");
                    new invokeFn(".yzm", fn);
                }
            });
        }
        var fn = function () {
            if (!checkMobile()) return;
            $(".yzm").unbind("click");
            myCaptcha.reload();
            myCaptcha.show()
        }
        $(".yzm").click(fn);
        function invokeSettime(obj) {
            var countdown = 60;
            settime(obj);
            function settime(obj) {
                if (countdown == 0) {
                    $(obj).click(fn);
                    $(obj).val("获取验证码");
                    countdown = 60;
                    return;
                } else {
                    $(obj).unbind("click");
                    $(obj).val("(" + countdown + ") s ");
                    countdown--;
                }
                setTimeout(function () {
                    settime(obj)
                }, 1000)
            }
        }

        function invokeFn(obj, fn) {
            $(obj).click(fn);
        }



        function checkMobile() {
            var creg = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[89])[0-9]{8}$/;
            var treg = /^09\d{8}$/;
            var mobile = $("#phone").val();
            if (mobile.length == 0) {
                layer.msg("手机号码不能为空");
                return false;
            }
            if (!(creg.test(mobile) || treg.test(mobile))) {
                layer.msg("请输入正确的手机号");
                return false;
            }
            else return true;

        }

    </script>
</body>


</html>
